// pages/clock/pages/jobText/index.js
const {
	http
} = require("../../../../utils/apiutils");
const util = require("../../../../utils/util")
const app = getApp()

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		jobData: {},
		id: 0,
		index: 0,
		videoList: [],
		showbord: false,
		urlArr: [],
		percentage:0
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.setData({
			id:options.id
		})
		this.getJobData(options.id)
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
		
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},
	getJobData: function (id) {
		var that = this;
		wx.showLoading({
			title: '加载中...',
		})
		http.getJobData(id,
			function (res) {
				wx.hideLoading()
				if (res.code == 0) {
					let videoList = [];
					let urlArr=[]
					if (res.data.imageList.length > 0) { 
						res.data.imageList.map(item => { 
								urlArr.push(item.src)
						})
					}
					let percentage = parseInt(res.data.registrationNumber/res.data.number*100)
					that.setData({
						jobData: res.data,
						videoList,
						urlArr,
						percentage:percentage<2?2:percentage
					})
					
				} else {
					wx.showToast({
						title: res.message,
						icon: "none",
					})
				}
			},
			function (err) {
				wx.hideLoading()
			})
	},
	
	funcClick(e) {
		let key = e.currentTarget.dataset.key * 1;
		let _this = this;
		switch (key) {
			case 1:
				_this.setData({
					showbord: true
				})
				setTimeout(_ => {
					_this.setData({
						showbord: false
					})
				}, 2000)
				break;
			case 3:
				wx.redirectTo({
					url:'/pages/clock/pages/jobvideo/index?id='+this.data.jobData.id
				})
				break;
			case 2:
				wx.navigateBack({
				  delta: 1,
				})
				break;
			case 4:
				wx.redirectTo({
					url:'/pages/clock/pages/jobimg/index?id='+this.data.jobData.id
				})
				break;
		}
	},
	viewImg(e) { 
		let index = e.currentTarget.dataset.idx;
		let url = e.currentTarget.dataset.url;
		wx.previewImage({
			current:url,
		  urls: this.data.urlArr,
		})
	}
})